package com.tt.service.impl;

import com.tt.entity.bo.ProvinceLineBO;
import com.tt.entity.vo.ProvinceLineVO;
import com.tt.mapper.RawApparentTotalMapper;
import com.tt.service.ProvinceLineService;
import com.tt.util.ConstUtil;
import com.tt.util.FuelEnum;
import com.tt.util.HandleDecimal;
import org.apache.tomcat.util.bcel.Const;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * <p>
 *
 * </p>
 *
 * @version 1.0
 * @auther sugarttt
 * @since 2022-11-10 10:33:10
 */
@Service
public class ProvinceLineServiceImpl implements ProvinceLineService {

    private final RawApparentTotalMapper rawApparentTotalMapper;

    public ProvinceLineServiceImpl(RawApparentTotalMapper rawApparentTotalMapper) {
        this.rawApparentTotalMapper = rawApparentTotalMapper;
    }

    @Override
    public ProvinceLineVO getProvinceLine(String beginYear, String endYear, Integer provinceId) {
        ProvinceLineVO provinceLineVO = new ProvinceLineVO();
        ArrayList<String> years = new ArrayList<>();
        ArrayList<String> legendData = new ArrayList<>();
        ArrayList<ArrayList<Double>> value = new ArrayList<>();

        for (int i = Integer.parseInt(beginYear); i <= Integer.parseInt(endYear); i++) {
            years.add(i + "");
        }

        legendData.add(ConstUtil.RAW_COAL);
        legendData.add(ConstUtil.CRUDE_OIL);
        legendData.add(ConstUtil.NATURAL_GAS);
        legendData.add(ConstUtil.CEMENT);

        for (int i = 0; i < 4; i++) {
            value.add(new ArrayList<>());
        }

        ArrayList<ProvinceLineBO> provinceLineBOS = rawApparentTotalMapper.getProvinceLine(beginYear, endYear, provinceId);
        Iterator<ProvinceLineBO> iterator = provinceLineBOS.iterator();

        ProvinceLineBO provinceLineBO;
        while (iterator.hasNext()) {
            provinceLineBO = iterator.next();

            value.get(0).add(HandleDecimal.handle(provinceLineBO.getCoalValue()));
            value.get(1).add(HandleDecimal.handle(provinceLineBO.getOilValue()));
            value.get(2).add(HandleDecimal.handle(provinceLineBO.getNaturalGasValue()));
            value.get(3).add(HandleDecimal.handle(provinceLineBO.getCement()));
        }


        provinceLineVO.setYears(years);
        provinceLineVO.setLegendData(legendData);
        provinceLineVO.setValue(value);
        return provinceLineVO;
    }
}
